﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MethodWorx.CMS.Workflow.Validate;
using MethodWorx.CMS.Workflow;
using Moq;
using MethodWorx.CMS.Plugins;


namespace MethodWorx.CMS.UI.Tests.Workflow
{
    [TestClass]
    public class ValidateWorkflowComponentTests
    {
        private class StubPlugin : Plugin
        {

        }

        [TestMethod]
        public void EnsureRequiredRaisesError()
        {
            var context = new Mock<IWorkflowExecutionContext>();
            var component = new ValidateWorkflowComponent(new StubPlugin());
            var config = new ValidateConfiguration();

            config.FieldName = "FieldName";
            config.ErrorMessage = "FieldName Is Required";

            context.Setup(m => m.GetWorkflowValue("FieldName"))
                .Returns("")
                .Verifiable();

            context.Setup(m => m.AddWorkflowError("FieldName", "FieldName Is Required"))
                .Verifiable();

            var result = component.Execute(context.Object, config);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.ExitBranch);
            Assert.AreEqual(true, result.StepCompleted);

            context.Verify();
        }
    }
}
